﻿using JT808.Protocol.Enums;
using JT808.Protocol.Interfaces;
using JT808.Protocol.Internal;
using JT808.Protocol.Extensions;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;
using JT808.Protocol.MessageBody;
using JT808.Protocol.Formatters;
using JT808.Protocol.MessagePack;
using System.Text.Json;
using JT808.Protocol.MessageBody.CarDVR;
using System.Linq;

namespace JT808.Protocol.Test.Simples
{
    public class Demo11
    {
        JT808Serializer JT808Serializer = new JT808Serializer(new DefaultGlobalConfig() { SkipCRCCode = true });

        [Fact]
        public void Test1()
        {
            byte[] bytes = "7E070401D90111111111118D1F00020100E90000000000000003016550E2060E84A8056402B20064200603172833010400054576030202B2EA5A00030507020F226300040503012A9198000504002469400006040035FF1E0007040008522800100E000400FA00BC00A500B000A202B2001202011B00130100001401190015020000001601F000170203D20018010F0019020047EC6560C00204F760D001456050017860F0015150B002005C6330015564600151649001005001010050020100500301005101017D01510201835104020FA6510501725106026E685107023A80510802FFFF510A0103510C0155510D0400000000511101025112010000E900000003016550BA060E8620056302BC005E200603172835010400054577030202BCEA5A00030507020F22AE00040503012A9198000504002469420006040035FF1E0007040008522800100E000400FA00890083008A009602BC001202011B00130100001401190015020000001601F000170203D20018010E0019020048EC6560C002050260D001466050017860F0015150B002005C6330015564600151649001005001010050020100500301005101017D01510201835104020FA65105017251060273185107023A60510802FFFF510A0103510C0155510D04000000005111010251120100807E".ToHexBytes();
            var package = JT808Serializer.Deserialize<JT808Package>(bytes);
            var bodies = package.Bodies as JT808_0x0704;
            //从第几个补传数据开始后续的包就有问题
            Assert.Equal(1,bodies.ErrorRemainPositions.FirstOrDefault(i=>i.Key==1).Key);
            Assert.Equal(2, bodies.Count);
            Assert.Single(bodies.Positions);
        }
    }
}
